package com.base.logistics.jdl.request;

import com.base.logistics.config.JdlConfig;
import com.base.logistics.jdl.bean.order.CancelOrderRequestParams;
import com.base.logistics.jdl.bean.order.CancelOrderResponse;
import com.base.logistics.jdl.bean.order.ReceiveOrderInfoRequestParams;
import com.base.logistics.jdl.bean.order.ReceiveOrderInfoResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * <pre>
 * 京东订单api接口实现
 * </pre>
 * @since 2021-02-21
 */
@Component
public class JdlOrderApiRequest {

    /**
     * 服务接口
     */
    private JdlRequestConfig jdlRequestConfig;

    @Autowired
    public JdlOrderApiRequest(JdlRequestConfig jdlRequestConfig) {
        this.jdlRequestConfig = jdlRequestConfig;
    }

    public ReceiveOrderInfoResponse receiveOrder(ReceiveOrderInfoRequestParams request) throws Exception {
        JdlConfig config = this.jdlRequestConfig.getConfig();
        request.getWaybillDTO().setJosPin(config.getPin());
        request.getWaybillDTO().setAppKey(config.getAppKey());
        request.getWaybillDTO().setCustomerCode(config.getCustomerCode());
        return this.jdlRequestConfig.execute(request,ReceiveOrderInfoResponse.class);
    }

    public CancelOrderResponse cancelOrder(CancelOrderRequestParams request) throws Exception {
        JdlConfig config = this.jdlRequestConfig.getConfig();
        request.getCancelRequest().setPin(config.getPin());
        request.getCancelRequest().setVendorCode(config.getCustomerCode());
        return this.jdlRequestConfig.execute(request, CancelOrderResponse.class);
    }
}
